package com.shelpe.services.algorithm.entity.mongo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import com.shelpe.services.algorithm.client.RankClient;
import com.shelpe.services.algorithm.entity.jpa.DevelopmentPlan;

import lombok.Data;

@Data
@Document(collection="keyword_realtime_rank_sync_logs")
public class KeywordRealtimeRankSyncLog {
	@Id
	private String id;
	@Indexed
	private long adgroupID;
	private DevelopmentPlan plan;
	
	private List<KeywordRankItem> items;
	@Indexed
	private Date syncTime;
	
	public void addItem(KeywordRankItem item){
		if(this.items == null){
			this.items = new ArrayList<KeywordRankItem>();
		}
		this.items.add(item);
	}
	
	public void setupID(long adgroupID, Date time){
		this.id = adgroupID + "-" +DateFormatUtils.format(time, "yyyyMMddHHmm");
	}
	
	@Data
	public static class KeywordRankItem{
		private String word;
		private long keywordID;
		private RankClient.KeywordRealtimeRankItem rank;
	}
	
}
